package com.mango.iot.gateway.http.core.config;

import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.filter.CharacterEncodingFilter;

import java.util.HashMap;

/**
 * 过滤器配置
 *
 * @author liangfeihu
 * @since 2021/8/20 16:56
 */
@Configuration
public class FilterConfig {

    @Bean
    public FilterRegistrationBean<CharacterEncodingFilter> getCharacterEncodingFilter() {
        CharacterEncodingFilter encodingFilter = new CharacterEncodingFilter();
        FilterRegistrationBean<CharacterEncodingFilter> registrationBean =
                new FilterRegistrationBean<CharacterEncodingFilter>();
        registrationBean.setFilter(encodingFilter);
        registrationBean.setInitParameters(new HashMap<String, String>() {
            private static final long serialVersionUID = 4109009467725333875L;
            {
                put("encoding", "UTF-8");
                put("forceEncoding", "true");
            }
        });
        registrationBean.addUrlPatterns("/*");
        return registrationBean;
    }

}
